import {Component, Input, OnInit} from "@angular/core";
import {Permission, PermissionDetail} from "@shared/models/Permission";
import {FileInfo} from "@shared/models/FileInfo";
import {AuthService} from "@core/service/AuthService";
import {UserGroup} from "@shared/models/UserInfo";

@Component({
  selector: 'bby-permission-card',
  templateUrl: './permission-card.html'
})
export class PermissionCard implements OnInit{

  constructor(private authService:AuthService) {

  }
  @Input()
  file:FileInfo=new FileInfo()
  permission=new Permission()
  groupList:UserGroup[]=[]
  ngOnInit(): void {
    if (this.file.permission){
      this.permission=this.file.permission
    }else {
      this.permission.open=false;
    }
    let userInfo = this.authService.getUserInfo();
    if (userInfo&&userInfo.userGroups) {
      this.groupList = Array.from(userInfo.userGroups.values())
    }
  }
  getFile(){
    this.file.permission=this.permission;
    return this.file
  }

  openPermission() {
    console.log(this.file)
    if (!this.file.permission){
      this.file.permission=this.permission
    }
  }
}
